import StringIO
import unittest

import slimconfig

class test_slimconfig(unittest.TestCase):
	def test_slimconfig_filename(self):
		def post(confdict):
			assert confdict['loadout'] == 50

		cfg = slimconfig.Config("test.conf", {'inject': 47, 'fuel': 3}, post)

		assert cfg['loadout'] == 50

	def test_slimconfig_fileobj(self):
		def post(confdict):
			assert confdict['loadout'] == 51

		cfgfile = StringIO.StringIO("loadout = inject + fuel + 1")

		cfg = slimconfig.Config(cfgfile, {'inject': 47, 'fuel': 3}, post)

		assert cfg['loadout'] == 51

	def test_slimconfig_badsyntax(self):
		cfgfile = StringIO.StringIO("loadout = inject :+ fuel + 2")

		self.assertRaises(slimconfig.ConfigurationError,
			slimconfig.Config,
			cfgfile, {'inject': 47, 'fuel': 3}
		)

	def test_slimconfig_badsyntax2(self):
		cfgfile = StringIO.StringIO("loadout = three")

		self.assertRaises(slimconfig.ConfigurationError,
			slimconfig.Config,
			cfgfile
		)
